from common import MemberEntity,SearchFilter, ArtistEntity
from dataaccess import MemberData, ArtistData
import DatabaseConnection

fl = None
cursor = None
conn = None

try:
    conn = DatabaseConnection.GetConnection()
    cursor = conn.cursor()
    start = 891
    fl = open(r"C:\Files\Mohsen\Academic\IU\B561-Advanced Database Systems\Project\Milestone 3\web2py\applications\radio\sql\parsedtables\populate_artist.sql","r")
    for i in range(891):
        query = fl.readline()
    while query<>"":
        cursor.execute(query.strip())
        conn.commit()
        query = fl.readline()
    fl.close()
    cursor.close()
    conn.close()
except Exception as e:
    conn.commit()
    fl.close()
    cursor.close()
    conn.close()
    raise e
    

##artistEntity = ArtistEntity.ArtistEntity(artistID=None,name='artist 2')
##artistData = ArtistData.ArtistData()
##print artistData.InsertArtist(artistEntity)

##memberEntity = MemberEntity.MemberEntity(username='mohsen',name='Mohsen Jafari',email='myemail@mail.com',userType=2,gender=None,address=None,birthDate=None,phone=None,regDate=None,userTypeDesc=None)
##memberData = MemberData.MemberData()

##memberData.InsertMember(memberEntity)

##memberData.DeleteMember(memberEntity.Username)
"""
memberEntity.Name='Mohsen JafariAsbagh'
memberEntity.Email='myemail@mail.net'
memberEntity.UserType=4
memberEntity.Gender='M'
memberEntity.Address='Bloomington, IN'
memberEntity.BirthDate="1982-07-24"
memberEntity.Phone='217-419-0222'
memberData.UpdateMember(memberEntity)


res = memberData.SelectMemberByID('mohsen')
print res.Name


sf = SearchFilter.SimpleFilter(MemberEntity.MemberEntity.ColumnNames.name,SearchFilter.ConditionType.Contain,'Jafari')
res = memberData.SelectMemberByFilter(sf)
print res[0].Name


csf = SearchFilter.ComplexFilter(SearchFilter.OperatorType.AND)
sf2 = SearchFilter.SimpleFilter(MemberEntity.MemberEntity.ColumnNames.gender,SearchFilter.ConditionType.Contain,'M')
csf.Filters.append(sf)
csf.Filters.append(sf2)
res = memberData.SelectMemberByFilter(csf)
print res[0].Name

"""
